package com.dmxh.controller;

import com.dmxh.result.Result;
import com.dmxh.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
 //  @RequestBody Map<String, String> orderprepare   最好不要使用map  当做入参   工作中会被喷的  没办法维护!
    @PostMapping("/crateOrder")          //注意token的名称要注意和前端axiosconfig.js中设置的一致否则拿不到请求头中的token
    public Result crateOrder(@RequestHeader String frontToken, @RequestBody OrderprePare orderprepare) {/*addressId地址id  paymentType支付类型*/
        return Result.ok().setData(this.orderService.crateOrder(frontToken, orderprepare));
    }

    /*MQ发送延迟消息  2分钟后如果订单还是未支付就将订单删除*/


//    @PostMapping("/queryOrderStatusAndDelete")
//    @Scheduled(fixedRate = 60000)/*每1分钟去查询订单表 如果订单是未支付就将订单删除*/
    public Result queryOrderStatusAndDelete() {
        return Result.ok().setData(this.orderService.queryOrderStatusAndDelete());
    }

    @PutMapping("/updateStatusByOutTradeNo")
    public boolean updateStatusByOutTradeNo(@RequestParam String outTradeNo){
        return orderService.updateStatusByOutTradeNo(outTradeNo);
    }
}
